<template>
  <view-box body-padding-bottom="5px">
    <empty tips="暂无活动" icon="icon-daipingjia" v-if="list !== null && list.length === 0"></empty>
    <template v-if="list !== null && list.length > 0">
      <row v-for="(item, index) in list" :key="index" :product="item" :type="type"></row>
    </template>
  </view-box>
</template>
<script>
  import { ViewBox } from 'vux'
  import Row from './components/Row'
  import Empty from '@/views/components/Empty'
  export default {
    name: 'promotion',
    data () {
      return {
        list: null,
        type: null
      }
    },
    components: {
      Row,
      ViewBox,
      Empty
    },
    mounted () {
      this.type = this.$route.params.type
      this._getData()
    },
    methods: {
      _getData () {
        this.$vux.loading.show()
        this.$http.get('/goods?is_on_sale=1&promotion=' + this.type).then((response) => {
          this.$vux.loading.hide()
          this.list = response.data.data
        }).catch((error) => {
          this.$vux.loading.hide()
          console.log(error)
        })
      }
    }
  }
</script>
